// 获取银行卡信息
// var getBankCard = "http://localhost:8080/hjcr-wechat/bankcard/getUserBankCrad";
var getBankCard = "./json/getBankCard.json";
$(document).ready(function(){
  // 获取银行卡信息
  $.get(getBankCard,{params:{userId:sessionStorage.userId}},function(res){
    if(res.serviceResult){
      var data = res.resultParm.list;
      var html = "";
      for (var i = 0; i < data.length; i++) {
        var select = "";
        if(data[i].id==sessionStorage.cardId || (sessionStorage.cardId===undefined && i==0)){select="active";}
        var str = data[i].number;
        var bank = bankName(data[i].bank);
        var num = str.substring(str.length-4,str.length);
        html += '<li class="list-item '+select+'" data-id="'+data[i].id+'">'+bank+'('+num+')<img src="img/right.png" alt=""></li>';
      }
      $("ul").empty().append(html);
    }
  });

  // 选择银行卡
  $(".bank-card-list").find("ul").on('click', '.list-item', function(){
    var id = $(this).attr("data-id");
    var list_item = $(".list-item");
    for(var i=0;i<list_item.length;i++){
      $(list_item[i]).removeClass("active");
    }
    $(this).addClass("active");
    sessionStorage.cardId = id;
    history.back();
  });
});
